package com.lijiajia.cloud.resource.sys.controller;

import com.lijiajia.cloud.resource.sys.client.TestClient;
import com.lijiajia.cloud.service.sys.test.TestException;
import com.lijiajia.cloud.service.sys.test.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

/**
 * root
 *
 * @author lijiajia
 * @since 2019-05-29
 */
@RestController
public class RootController {

    @GetMapping("/auth")
    public Authentication authentication(Authentication authentication) {
        return authentication;
    }

    @Slf4j
    @RestController
    static class TestController implements TestService {
        private TestClient orderTestClient;
        AtomicLong num = new AtomicLong();

        TestController(TestClient orderTestClient) {
            this.orderTestClient = orderTestClient;
        }

        @Override
        public String test(String code) {
            if (code != null && code.equals("sys")) {
                throw new TestException();
            }
            log.debug("cloud-sys:/test num:{}", num.incrementAndGet());
            return orderTestClient.test(code);
        }
    }

}
